<template>
  <div class="home">
    <div class="hom">
      <div class="dv">{{nian}}年</div>
      <div class="dv">{{nest}}月</div>
      <button class="but" @click="jia">上一月</button>
      <button class="but" @click="jian">下一月</button>
      <div class="dvd">
        <div class="rq" v-for="(item,index) in dase" :key="index">
          {{ item }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dase:"",
      nest:1,
      sent:0,
      nian:2021,
    };
  },
  methods: {
    jian(){
      this.nest++;
      if(this.nest == 13){
        this.nest = 1;
        this.nian++;
      }
      // console.log(this.nian);
      this.dase = new Date(this.sent, this.nest, 0).getDate();
      // console.log(new Date(this.sent, this.nest, 0).getDate());
    },
    jia(){
      this.nest--;
      if(this.nest == 0){
        this.nest = 12;
        this.nian--;
      }
      // console.log(this.nian);
      this.dase = new Date(this.sent, this.nest, 0).getDate();
    },
  },
  mounted() {
      this.dase = new Date(this.sent, this.nest, 0).getDate();
      if(this.nest == 0){
        this.nest = 12;
      }
      if(this.nest == 12){
        this.nest = 0;
      }
      // console.log(this.dase);
  },
};
</script>
<style lang="scss">
.hom {
  width: 460px;
  height: 300px;
  border: 1px solid rgb(160, 155, 155);
  border-radius: 10px;
  display: flex;
  flex-wrap: wrap;
  padding: 5px;
  margin: 100px auto;
  .dv {
    width: 34.5%;
    height: 30px;
    border: 1px solid rgb(160, 155, 155);
    border-radius: 5px;
    line-height: 30px;
    text-align: center;
  }
  .but {
    width: 15%;
    height: 32px;
    font-size: 10px;
  }
  .dvd {
    width: 460px;
    height: 250px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 10px;
  }
  .rq {
    width: 60px;
    height: 45px;
    box-sizing: border-box;
    margin: 2.8px;
    border: 1px solid rgb(160, 155, 155);
    border-radius: 3px;
    line-height: 50px;
    font-size: 10px;
  }
}
</style>
